<template>
	<view class="app">
		<u-form :model="data.formData" ref="form1">
			<u-form-item left-icon="account" label="姓名" prop="name"><u-input v-model="data.formData.name" /></u-form-item>
			<u-form-item left-icon="home" label="地址" prop="intro"><u-input v-model="data.formData.address" /></u-form-item>
			<u-form-item left-icon="phone" label="电话" prop="phone"><u-input v-model="data.formData.phone" /></u-form-item>
		</u-form>

		<u-button type="info" plain :ripple="true" @click="submit">去支付</u-button>
	</view>
</template>

<script setup>
	import { ref, reactive, onMounted, unref, computed, watch } from 'vue';
	import { onLoad, onReady } from '@dcloudio/uni-app';
	import {replaceOrderApi} from '../../api/order.js';
	const form1 = ref();
	const data = reactive({
		formData: {
			name: "",
			address: "",
			phone: "",
			price: uni.getStorageSync("price"),
			goodsId: uni.getStorageSync("goodsId"),
			orderUser:uni.getStorageSync("userId")
		},
		rules: {
			name: [{
				required: true,
				message: '请输入姓名',
				// 可以单个或者同时写两个触发验证方式 
				trigger: ['change', 'blur'],
			}],
			intro: [{
				min: 5,
				message: '输入地址',
				trigger: 'change'
			}],
			phone: [{
				min: 5,
				message: '请输入电话',
				trigger: 'change'
			}],
		}
	});

	onReady(() => {
		form1.value.setRules(data.rules);
	});

	const submit = async (e) => {
		//uni.getStorageSync("userId"),
		uni.setStorageSync("name",data.formData.name),
		uni.setStorageSync("address",data.formData.address),
		uni.setStorageSync("phone",data.formData.phone),
		form1.value.validate(valid => {
			let res =  replaceOrderApi(data.formData)
			if(res && res.code == 200){
				uni.showToast({
					title:"goods",
					icon:'none'
				})
			}
			if (valid) {
			   /*wx.requestPayment
			   (
			     {
			       "timeStamp": "1414561699",
			       "nonceStr": "5K8264ILTKCH16CQ2502SI8ZNMTM67VS",
			       "package": "prepay_id=wx201410272009395522657a690389285100",
			       "signType": "RSA",
			       "paySign": "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==",
			       "success":function(res){},
			       "fail":function(res){},
			       "complete":function(res){}
			     }
			   )*/
				uni.showToast({
					title: "验证通过",
					icon: 'none',
				});
				console.log('验证通过');
				uni.navigateTo({
					url:"../index/index"
				})
			} else {
				console.log('验证失败');
			}
		});
	}
	
</script>
